package com.qijian.common.config.mybatisplus;

import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
import com.baomidou.mybatisplus.core.metadata.TableInfo;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class MySqlInjector extends DefaultSqlInjector {
    @Override
    public List<AbstractMethod> getMethodList(Class<?> mapperClass, TableInfo tableInfo) {
        List<AbstractMethod> myInjectors = new ArrayList<AbstractMethod>() {{
            add(new LogicDeleteByIdWithFill());
            add(new LogicDeleteBatchByIdsWithFill());
            add(new LogicDeleteByMapWithFill());
            add(new LogicDeleteByEntityWithFill());
        }};
        List<AbstractMethod> methodList = super.getMethodList(mapperClass, tableInfo);
        Map<String, AbstractMethod> my = myInjectors.stream().collect(Collectors.toMap(a -> a.getClass().getSuperclass().getName(), a -> a));
        Map<String, AbstractMethod> other = methodList.stream().collect(Collectors.toMap(a -> a.getClass().getName(), a -> a));
        my.keySet().forEach(other::remove);
        myInjectors.addAll(other.values());
        return myInjectors;
    }
}
